﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Objects;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;

namespace IBS.Bll.Tools
{
    public static class ServiceHelper
    {
        public static IList<T> GetByCriteria<T>(this IObjectSet<T> set, int? pageNumber, Func<T, bool> predicate =null )
            where T:class 
        {
            var myPredicate = predicate?? (x=>true);
            var resultByCriteria = set
                          .Where(myPredicate);
            if (pageNumber.HasValue)
            {
                var page = pageNumber.Value;
                resultByCriteria =
                    resultByCriteria
                    .Skip((page - 1) * Configuration.RecordPerPage)
                    .Take(Configuration.RecordPerPage);
            }
            return resultByCriteria.ToList();
        }
    }
}
